/************************************************************************
 * Este archivo, representa la interfaz del pago de un cliente
 * junto con las acciones asociadas a los eventos de cada componente
 * 
 * @system: veco-system
 * @description: Sistema de control vehicular
 * @version: 1.0
 * @Copyright © 2013 
 * 
 * @authores:
 * 
 *      > Alberione, Fernando    <falberione_037@gmail.com>
 * 
 *      > Boretto, Martin        <martinboretto@gmail.com>
 * 
 *      > Lenarduzzi, Federico   <fedeatenas@gmail.com>
 * 
 *      > Ocampo, Emanuel        <eocampo86@gmail.com>
 *
 *************************************************************************/
package Interfaces;

import SistemaCocheras.manejadorEstadoCliente;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.Connection;
import javax.swing.JOptionPane;


public class pagoCliente extends javax.swing.JFrame {

    Connection conexion;
    String dniUsuario;

    
    // ---------------------------------------------------------
    // ------- Seccion de constructores de la clase
    // ---------------------------------------------------------    

    /**
     * Constructor vacio 
     */
    public pagoCliente() {
        initComponents();
        centrarJFrame();
    }// Fin Constructor
    
    
    /**
     * Constructor NO vacio
     * @param con Representa la conexion de la base de datos
     * @param dni Representa el dni del usuario
     */
    public pagoCliente(Connection con, String dni) {
        this.conexion = con;
        this.dniUsuario = dni;
        initComponents();
        centrarJFrame();
    }// Fin Constructor
    
    
    // ---------------------------------------------------------
    // ------- Seccion de metodos publicos 
    // --------------------------------------------------------- 
    
    /**
     * Metodo encargado de levantar una instancia de la clase 
     * @param args 
     */
     public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new pagoCliente().setVisible(true);
            }
        });
    }// Fin main
     
     
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelDNI = new javax.swing.JLabel();
        campoDNI = new javax.swing.JTextField();
        BotonAceptar = new javax.swing.JButton();
        BotonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("B&B - Registrar pago de cliente");

        jLabelDNI.setText("DNI del cliente (*) :");

        BotonAceptar.setText("Aceptar");
        BotonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonAceptarActionPerformed(evt);
            }
        });

        BotonCancelar.setText("Cancelar");
        BotonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelDNI)
                        .addGap(28, 28, 28)
                        .addComponent(campoDNI, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BotonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(BotonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {BotonAceptar, BotonCancelar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelDNI)
                    .addComponent(campoDNI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BotonAceptar)
                    .addComponent(BotonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {BotonAceptar, BotonCancelar});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    // ---------------------------------------------------------
    // ------- Seccion de metodos privados 
    // ---------------------------------------------------------    
    
    /**
     * Funcion encargada de centrar el dialogo en la pantalla
     */
    private void centrarJFrame(){
        Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frame = this.getSize();
        this.setLocation((pantalla.width-frame.width)/2, (pantalla.height-frame.height)/2);
    }// Fin centrarJFrame
    
    
    /**
     * Metodo encargado de realizar lo necesario (crear vehiculo) a 
     * traves del boton aceptar
     * @param evt Representa el evento del click
     */
    private void BotonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonAceptarActionPerformed
        try {
            manejadorEstadoCliente mec = new manejadorEstadoCliente(this.conexion);
            String dni = this.campoDNI.getText();
            double monto = mec.marcarPago(dni, this.dniUsuario);
            JOptionPane.showMessageDialog(null,"Se ha registrado correctamente el pago del importe: $"+monto, "Sistema de Cocheras B&B",JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,"Ha ocurrido un error interno: "+ ex, "Sistema de Cocheras B&B",JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_BotonAceptarActionPerformed

    
    /**
     * Metodo encargado de cerrar la interfaz a traves del boton cancelar
     * @param evt Representa el evento del click
     */
    private void BotonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonCancelarActionPerformed
        this.dispose();
}//GEN-LAST:event_BotonCancelarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonAceptar;
    private javax.swing.JButton BotonCancelar;
    private javax.swing.JTextField campoDNI;
    private javax.swing.JLabel jLabelDNI;
    // End of variables declaration//GEN-END:variables

}// Fin clase pagoCliente
